import BaseApi from "@/api/BaseApi.ts";
import type JvmArgumentsResp from "@/view/sys/monitor/type/resp/JvmArgumentsResp.ts";
import type MemoryPoolDetailResp from "@/view/sys/monitor/type/resp/MemoryPoolDetailResp.ts";
import type ClassLoadingDetailResp from "@/view/sys/monitor/type/resp/ClassLoadingDetailResp.ts";
import type GcResultResp from "@/view/sys/monitor/type/resp/GcResultResp.ts";
import type DiskInfoResp from "@/view/sys/monitor/type/resp/DiskInfoResp.ts";
import type DatabaseInfoRealtimeResp from "@/view/sys/monitor/type/resp/DatabaseInfoRealtimeResp.ts";
import type GcInfoResp from "@/view/sys/monitor/type/resp/GcInfoResp.ts";
import type ThreadInfoResp from "@/view/sys/monitor/type/resp/ThreadInfoResp.ts";
import type OperateSystemBasicResp from "@/view/sys/monitor/type/resp/OperateSystemBasicResp.ts";
import type JvmBasicResp from "@/view/sys/monitor/type/resp/JvmBasicResp.ts";

class SysMonitorApi extends BaseApi {

    constructor() {
        super("/sys/monitor")
    }

    /**
     * 获取JVM启动时的所有参数，包括内存、GC等配置
     */
    arguments = () => {
        return this.get<JvmArgumentsResp>('arguments')
    }

    /**
     * 获取堆内存区域信息（按区分组）
     * 按新生代、老年代等区域分组显示堆内存使用情况
     */
    heapPools = () => {
        return this.get<Record<string, MemoryPoolDetailResp[]>>('heapPools')
    }

    /**
     * 获取所有内存池信息
     * 获取包括堆和非堆的所有内存池详细信息
     */
    memoryPools = () => {
        return this.get<MemoryPoolDetailResp[]>('memoryPools')
    }

    /**
     * 获取类加载详细信息
     * 获取已加载、总加载、已卸载的类统计信息
     */
    classLoading = () => {
        return this.get<ClassLoadingDetailResp>('classLoading')
    }

    /**
     * 获取磁盘使用情况
     * 获取所有磁盘分区的使用情况
     */
    disk = () => {
        return this.get<DiskInfoResp>('disk')
    }

    /**
     * 获取数据库连接池信息
     * 获取数据库连接池的连接数、使用率等信息
     */
    database = () => {
        return this.get<DatabaseInfoRealtimeResp>('database')
    }

    /**
     * 获取GC信息
     * 获取垃圾回收器的统计信息
     */
    getGcInfo = () => {
        return this.get<GcInfoResp>('getGcInfo')
    }

    /**
     * 获取线程信息
     * 获取JVM线程统计信息
     */
    threads = () => {
        return this.get<ThreadInfoResp>('threads')
    }


    /**
     * 获取操作系统基础信息
     */
    operateSystemBasic = () => {
        return this.get<OperateSystemBasicResp>('operateSystemBasic')
    }

    /**
     * 获取JVM基本信息
     */
    jvmBasic = () => {
        return this.get<JvmBasicResp>('jvmBasic')
    }

    /**
     * 强制垃圾回收
     * 手动触发JVM垃圾回收，返回GC执行结果
     */
    doGc = () => {
        return this.get<GcResultResp>('doGc')
    }

}

export default new SysMonitorApi()